#!/usr/bin/python
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""GIT password response

Wrapper for the legacy password checking responses. It builds the JSON response
which is sent back to the identity toolkit widget.
"""

__author__ = 'Xin Zhou(zhounew@google.com)'

from git.json import git_json
from git.logic import git_base_response

class GitPasswordResponse(git_base_response.GitBaseResponse):
  STATUS_OK = 'ok'
  STATUS_PASSWORD_ERROR = 'passworderror'
  STATUS_FEDERATED = 'federated'
  STATUS_EMAIL_NOT_EXIST = 'emailnotexist'
  
  def __init__(self):
    self.status_ = ''
    self.display_name_ = ''
    self.photo_url_ = ''
    self.status_array_ = [GitPasswordResponse.STATUS_OK,
                          GitPasswordResponse.STATUS_PASSWORD_ERROR,
                          GitPasswordResponse.STATUS_FEDERATED,
                          GitPasswordResponse.STATUS_EMAIL_NOT_EXIST]

  def SetStatus(self, status):
    if status in self.status_array_:
        self.status_ = status
  
  def SetDisplayName(self, display_name):
    self.display_name_ = display_name
  
  def SetPhotoUrl(self, photo_url):
    self.photo_url_ = photo_url
  
  def ToJson(self):
    json = {}
    json['status'] = self.status_
    if self.display_name_:
      json['displayName'] = self.display_name_
    if self.photo_url_:
      json['photoUrl'] = self.photo_url_
    return git_json.GitJson().dumps(json)